<template>
  <div>
    <van-nav-bar
      fixed
      placeholder
      safe-area-inset-top
      title="当地新闻"
      left-arrow
      @click-left="back"
    />
    <div
      v-for="(item, index) in newslist"
      :key="index"
      @click="todetail(item.id)"
      class="news"
    >
      <div>
        <div class="title van-multi-ellipsis--l2">{{ item.title }}</div>
        <div class="show">
          <div>
            <van-icon class="tip" name="underway-o" /><span
              style="margin-right: 15px"
              >{{ item.createTime }}</span
            >
          </div>
          <div>
            <span class="tip">来源:</span
            ><span class="van-ellipsis from">{{ item.source }}</span>
          </div>
        </div>
      </div>
      <van-image
        width="120px"
        height="100px"
        lazy-load
        :src="item.imageUrl"
        fit="cover"
        radius="5px"
      />
    </div>
  </div>
</template>

<script>
import { getNewslist } from "../../apis/buy.js";
import local from "../../utils/local";
export default {
  data() {
    return {
      currentPage: 1,
      perPage: 10,
      newslist: [],
    };
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    todetail(i) {
      this.$router.push({ path: "/newsdetail", query: { id: i } });
    },
    async getlist() {
      await getNewslist({
        currentPage: this.currentPage,
        perPage: this.perPage,
        adcode: local.get("adcode"),
      }).then((res) => {
        this.newslist = res.result.list;
        console.log(res.result.list);
      });
    },
  },
  created() {
    this.getlist();
  },
};
</script>

<style lang="less" scoped>
.news {
  margin: 0 15px;
  padding: 10px 0;
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .title {
      font-size: 16px;
      color: #333;
      font-weight: bold;
      width: 220px;
      word-wrap: break-word;
    }
    .show {
      display: flex;
      width: 220px;
      > div {
        display: flex;
        align-items: center;
        color: #666;
        font-size: 13px;
        .tip {
          margin-right: 3px;
        }
        .from {
          width: 80px;
        }
      }
    }
  }
}
</style>